package action.agent;

import org.apache.struts2.ServletActionContext;

import security.MySecurityContextHandle;
import service.interf.IIfwAgentDevInfo;
import action.common.MyBaseAction;

import com.opensymphony.xwork2.ModelDriven;

import dao.pojo.IfwAgentDevInfo;

public class IfwAgentDevInfoAction extends MyBaseAction<IfwAgentDevInfo>
		implements ModelDriven<IfwAgentDevInfo> {

	private static final long serialVersionUID = 1L;

	private IIfwAgentDevInfo iIfwAgentDevInfo;

	public void setiIfwAgentDevInfo(IIfwAgentDevInfo iIfwAgentDevInfo) {
		this.iIfwAgentDevInfo = iIfwAgentDevInfo;
	}

	public IfwAgentDevInfoAction() {
		super(IfwAgentDevInfo.class);
	}

	public IfwAgentDevInfo getModel() {
		return model;
	}

	/**
	 * 初始化列表
	 */
	public void getlist() {
		String x = "";
		try {
			x = iIfwAgentDevInfo.getList(model);
		} catch (Exception e) {
			e.printStackTrace();
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient(ServletActionContext.getResponse(), x);
	}

	/**
	 * 添加网吧/企业
	 */
	public void addInCafe() {
		String x = "";
		try {
			Integer agentIndex = MySecurityContextHandle.getAgentIndex();
			x = iIfwAgentDevInfo.addInCofe(model, agentIndex);
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

	/**
	 * 删除网吧/企业
	 */
	public void delInCafe() {
		String x = "";
		try {
			Integer agentIndex = MySecurityContextHandle.getAgentIndex();
			x = iIfwAgentDevInfo.delInCofe(model.getIds(), agentIndex);
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

	/**
	 * 查询--ID
	 */
	public void findbyId() {
		String x = "";
		try {
			x = iIfwAgentDevInfo.findByProperty("IfwAgentDevInfo",
					"*,ifwAgentRegInfo.agentIndex(agentIndex)", "json", true,
					new String[] { "agentDevIndex", "enabled" }, new Object[] {
							model.getAgentDevIndex(), true }, null, null, model
							.getPage(), model.getRows());
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

	/**
	 * 查询--SN
	 */
	public void findbySN() {
		String x = "";
		try {
			x = iIfwAgentDevInfo.findByProperty("IfwAgentDevInfo", "*", "json",
					true, new String[] { "sn", "enabled" }, new Object[] {
							model.getSn(), true }, null, null, model.getPage(),
					model.getRows());
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}

	/**
	 * 修改基本信息
	 */
	public void changeAgent() {
		String x = "";
		try {
			x = iIfwAgentDevInfo.changeAgentDev(model);
		} catch (Exception e) {
			x = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), x);
	}
}
